package com.sti.platform.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.aisino.core.server.BaseService;
import com.aisino.tools.util.Assert;
import com.aisino.tools.util.RandomUtils;
import com.aisino.tools.util.StringUtils;
import com.sti.platform.dao.ResourceDao;
import com.sti.platform.model.Resource;
import com.sti.platform.service.ResourceService;

@Service
public class ResourceServiceImpl extends BaseService implements ResourceService {
	
	@Autowired
	private ResourceDao resourceDao;

	@Override
	public String addResource(String name, String url, String code, String type, String isenable) {
		// TODO Auto-generated method stub

		// name的非空校验
		Assert.isTrue(StringUtils.hasText(name), "name不能为空.");
		//
		Assert.isTrue(StringUtils.hasText(url), "url不能为空.");

		Resource res = new Resource();
		res.setName(name);
		res.setUrl(url);
		res.setCode(code);
		res.setType(type);
		res.setEnable(isenable);

		super.save(res);

		return res.getId();
	}

	@Override
	public String addResource(Resource resource) {
		// TODO Auto-generated method stub
		// name的非空校验
		Assert.isTrue(StringUtils.hasText(resource.getName()), "name不能为空.");
		//
		Assert.isTrue(StringUtils.hasText(resource.getUrl()), "url不能为空.");
		
		resource.setUserId(RandomUtils.randomUUID());
		
		resource.setOrganId(RandomUtils.randomUUID());
		
		super.save(resource);

		return resource.getId();
	}

	@Override
	public List<Resource> get() {
		// TODO Auto-generated method stub
		
		List<Resource> list=resourceDao.getResource();
		
		return list;
	}

}
